<template>
  <view class="common-components" v-if="commonVmList.length">
    <biz-switch-env-config
      v-if="checkInCommonVmList('toast')"
      ref="toast"
    ></biz-switch-env-config>
  </view>
</template>

<script setup>
const commonVmList = ref([])

const checkInCommonVmList = (ref) => {
  return commonVmList.value.includes(ref)
}

const refList = ref({})

const setCommonVmList = (ref) => {
  if (!checkInCommonVmList(ref)) {
    commonVmList.value.push(ref)
  }
}
const getRef = (ref) => {
  setCommonVmList(ref)
  return new Promise((reslove) => {
    nextTick(() => {
      reslove(refList.value.refs[ref])
    })
  })
}

onMounted(async () => {
  refList.value = getCurrentInstance()
})

defineExpose({
  getRef
})
</script>
